import urllib.request
import json
import turtle
import time

url = 'http://www.luohanye.com/astros.json'
response = urllib.request.urlopen(url)
result = response.read().decode('utf-8')
astros = json.loads(result)
print('People in Space:', astros['number'])

people = astros['people']
for p in people:
    print(p['name'])

print('------------------------')
# Where is the ISS?
url = 'http://www.luohanye.com/iss-now.json'
response = urllib.request.urlopen(url)
result = response.read().decode('utf-8')
issNow = json.loads(result)

location = issNow['iss_position']
lat = float(location['latitude'])
lon = float(location['longitude'])
print('Latitude', repr(lat))
print('Longitude', repr(lon))

screen = turtle.Screen()
screen.setup(720, 360)
screen.setworldcoordinates(-180, -90, 180, 90)
screen.bgpic('img/map.gif')

screen.register_shape('img/iss.gif')
iss = turtle.Turtle()
iss.shape('img/iss.gif')
iss.setheading(90)
# 提起画笔
iss.penup()
# 移动位置
iss.goto(lon, lat)

# Space Center, Houston
lat = 29.5502
lon = -95.097

location = turtle.Turtle()
location.penup()
location.color('yellow')
location.goto(lon, lat)
location.dot(5)
location.hideturtle()

# 计算
url = 'http://api.open-notify.org/iss-pass.json?lat=' + str(lat) + '&lon=' + str(lon)
response = urllib.request.urlopen(url)
result = json.loads(response.read().decode('utf-8'))

# print result
over = result['response'][1]['risetime']
time1 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(over))
print(time1)
# location.write(time.ctime(over))
location.write(time1)



